/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.foxline.model;

import br.com.foxline.enums.CivilStatus;
import br.com.foxline.enums.Gender;
import br.com.foxline.validator.CPF;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Past;
import javax.validation.constraints.Size;
import org.hibernate.validator.constraints.NotEmpty;

/**
 *
 * @author luciano
 */
@Entity
public class Customer implements Serializable{
    
    private static final long serialVersionUID = 1L;
    
    @Id
    @SequenceGenerator(sequenceName = "seq_customer", name = "seq_customer", allocationSize = 1)
    @GeneratedValue(generator = "seq_customer", strategy = GenerationType.SEQUENCE)
    private Long id;
    
    @Column(length=250)
    private String name;
    
    @Enumerated(EnumType.STRING)
    private Gender gender;
    
    private String rg;
    @CPF
    private String cpf;
     
    private String profession;
    @Past(message="Data de Nascimento deve ser anterior a atual")
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date dateOfBirth;
    private String nationality;
    
    @Enumerated(EnumType.STRING)
    private CivilStatus civilStatus;
    
    private String email;
    private String fixedPhone;
    private String celPhone;
    @Size(min=1,  message="O Cliente deve possuir um endereço.")
    @OneToMany(cascade= CascadeType.ALL) 
    private List<Address> addresses;
    
    @OneToOne 
    private Customer spouse;
    
    @OneToOne
    private SystemUser systemUser;
    
    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
    private Date createdAt;
    
    @OneToMany(cascade= CascadeType.ALL) 
    private List<Annex> annexs;

    public List<Address> getAddresses() {
        return addresses;
    }
 
    public void setAddresses(List<Address> addresses) {
        this.addresses = addresses;
    }

    public List<Annex> getAnnexs() {
        return annexs;
    }

    public void setAnnexs(List<Annex> annexs) {
        this.annexs = annexs;
    }

    public String getCelPhone() {
        return celPhone;
    }

    public void setCelPhone(String celPhone) {
        this.celPhone = celPhone;
    }

    public CivilStatus getCivilStatus() {
        return civilStatus;
    }

    public void setCivilStatus(CivilStatus civilStatus) {
        this.civilStatus = civilStatus;
    }

    public String getCpf() {
        return cpf;
    }

    public void setCpf(String cpf) {
        this.cpf = cpf;
    }

    public Date getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(Date createdAt) {
        this.createdAt = createdAt;
    }

    public Date getDateOfBirth() {
        return dateOfBirth;
    }

    public void setDateOfBirth(Date dateOfBirth) {
        this.dateOfBirth = dateOfBirth;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getFixedPhone() {
        return fixedPhone;
    }

    public void setFixedPhone(String fixedPhone) {
        this.fixedPhone = fixedPhone;
    }

    public Gender getGender() {
        return gender;
    }

    public void setGender(Gender gender) {
        this.gender = gender;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getNationality() {
        return nationality;
    }

    public void setNationality(String nationality) {
        this.nationality = nationality;
    }

    public String getProfession() {
        return profession;
    }

    public void setProfession(String profession) {
        this.profession = profession;
    }

    public String getRg() {
        return rg;
    }

    public void setRg(String rg) {
        this.rg = rg;
    }

    public Customer getSpouse() {
        return spouse;
    }

    public void setSpouse(Customer spouse) {
        this.spouse = spouse;
    }

    public SystemUser getSystemUser() {
        return systemUser;
    }

    public void setSystemUser(SystemUser systemUser) {
        this.systemUser = systemUser;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Customer other = (Customer) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
            return false;
        }
        if (this.gender != other.gender) {
            return false;
        }
        if ((this.rg == null) ? (other.rg != null) : !this.rg.equals(other.rg)) {
            return false;
        }
        if ((this.cpf == null) ? (other.cpf != null) : !this.cpf.equals(other.cpf)) {
            return false;
        }
        if ((this.profession == null) ? (other.profession != null) : !this.profession.equals(other.profession)) {
            return false;
        }
        if (this.dateOfBirth != other.dateOfBirth && (this.dateOfBirth == null || !this.dateOfBirth.equals(other.dateOfBirth))) {
            return false;
        }
        if ((this.nationality == null) ? (other.nationality != null) : !this.nationality.equals(other.nationality)) {
            return false;
        }
        if (this.civilStatus != other.civilStatus) {
            return false;
        }
        if ((this.email == null) ? (other.email != null) : !this.email.equals(other.email)) {
            return false;
        }
        if ((this.fixedPhone == null) ? (other.fixedPhone != null) : !this.fixedPhone.equals(other.fixedPhone)) {
            return false;
        }
        if ((this.celPhone == null) ? (other.celPhone != null) : !this.celPhone.equals(other.celPhone)) {
            return false;
        }
        if (this.addresses != other.addresses && (this.addresses == null || !this.addresses.equals(other.addresses))) {
            return false;
        }
        if (this.spouse != other.spouse && (this.spouse == null || !this.spouse.equals(other.spouse))) {
            return false;
        }
        if (this.systemUser != other.systemUser && (this.systemUser == null || !this.systemUser.equals(other.systemUser))) {
            return false;
        }
        if (this.createdAt != other.createdAt && (this.createdAt == null || !this.createdAt.equals(other.createdAt))) {
            return false;
        }
        if (this.annexs != other.annexs && (this.annexs == null || !this.annexs.equals(other.annexs))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 23 * hash + (this.id != null ? this.id.hashCode() : 0);
        hash = 23 * hash + (this.name != null ? this.name.hashCode() : 0);
        hash = 23 * hash + (this.gender != null ? this.gender.hashCode() : 0);
        hash = 23 * hash + (this.rg != null ? this.rg.hashCode() : 0);
        hash = 23 * hash + (this.cpf != null ? this.cpf.hashCode() : 0);
        hash = 23 * hash + (this.profession != null ? this.profession.hashCode() : 0);
        hash = 23 * hash + (this.dateOfBirth != null ? this.dateOfBirth.hashCode() : 0);
        hash = 23 * hash + (this.nationality != null ? this.nationality.hashCode() : 0);
        hash = 23 * hash + (this.civilStatus != null ? this.civilStatus.hashCode() : 0);
        hash = 23 * hash + (this.email != null ? this.email.hashCode() : 0);
        hash = 23 * hash + (this.fixedPhone != null ? this.fixedPhone.hashCode() : 0);
        hash = 23 * hash + (this.celPhone != null ? this.celPhone.hashCode() : 0);
        hash = 23 * hash + (this.addresses != null ? this.addresses.hashCode() : 0);
        hash = 23 * hash + (this.spouse != null ? this.spouse.hashCode() : 0);
        hash = 23 * hash + (this.systemUser != null ? this.systemUser.hashCode() : 0);
        hash = 23 * hash + (this.createdAt != null ? this.createdAt.hashCode() : 0);
        hash = 23 * hash + (this.annexs != null ? this.annexs.hashCode() : 0);
        return hash;
    }

    @Override
    public String toString() {
        return "Customer{" + "id=" + id + ", name=" + name + ", gender=" + gender + ", rg=" + rg + ", cpf=" + cpf + ", profession=" + profession + ", dateOfBirth=" + dateOfBirth + ", nationality=" + nationality + ", civilStatus=" + civilStatus + ", email=" + email + ", fixedPhone=" + fixedPhone + ", celPhone=" + celPhone + ", addresses=" + addresses + ", spouse=" + spouse + ", systemUser=" + systemUser + ", createdAt=" + createdAt + ", annexs=" + annexs + '}';
    }

    
}
